home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
-
- StampUI.c
-
- This file is furnished to you by Adobe Systems Incorporated
- under the terms of the Acrobat(r) Plug-ins Software
- Development Kit License Agreement.
-
- Copyright (C) 1994-1997, Adobe Systems Inc. All Rights Reserved.
-
-
- Implementation of the Stamper plug-in's Stamping tool
- and associated UI elements.
-
- ******************************************************************************/
-
- #include "stampui.h"
- #include "stamppr.h"
- #include "stamper.h"
- #include "stampah.h"
-
- #include <string.h>
-
- #include "AVCalls.h"
- #include "CorCalls.h"
- #include "PDCalls.h"
-
- static AVCursor stamperCursor;
- static AVToolRec stamperTool;
- static AVToolButton stamperToolButton;
- static AVMenuItem stamperMenuItem;
- static AVMenuItem aboutMenuItem ;
- static void SetUpMenuItem(void);
-
- static ACCB1 void ACCB2 StampAbout(void *data);
-
- /* Stamper AVTool callbacks */
- static ACCB1 ASAtom ACCB2 StamperToolGetType(AVTool tool)
- {
- return Stamper_K;
- }
-
- static ASBool gStamperIsPersistent;
- static ACCB1 void ACCB2 StamperActivate(AVTool tool, ASBool persistent)
- {
- gStamperIsPersistent = persistent;
- }
-
- static ACCB1 ASBool ACCB2 StamperAdjustCursor(AVTool tool, AVPageView pageView, Int16 x, Int16 y)
- {
- PDAnnot hitAnnot;
- ASBool shiftKeyIsDown = ((AVSysGetModifiers() & AV_SHIFT) != 0);
- /* Defer to the annotation, if any */
- if (!shiftKeyIsDown && AVPageViewIsAnnotAtPoint(pageView, x, y, &hitAnnot))
- return false;
-
- AVSysSetCursor(stamperCursor);
- return true;
- }
-
- static ACCB1 ASBool ACCB2 StamperDoClick(AVTool tool, AVPageView pageView,
- Int16 xHit, Int16 yHit,
- Int16 flags,
- Int16 clickNo)
- {
-
- PDAnnot hitAnnot;
- ASBool shiftKeyIsDown = ((AVSysGetModifiers() & AV_SHIFT) != 0);
-
- if (!shiftKeyIsDown && AVPageViewIsAnnotAtPoint(pageView, xHit, yHit, &hitAnnot))
- return false;
-
- if (CreateAppleScriptAnnotationAt(pageView, xHit, yHit))
- {
- /* If we're not in a persistent mode, select the last active
- ** tool now that the user's done with the Stamper.
- */
- if (!gStamperIsPersistent)
- AVAppSetActiveTool(AVAppGetLastActiveTool(), true);
- }
-
- return true;
- }
-
-
- /* setStamperTool
- ** This is the AVExecuteProc associated with the AVMenuItem and AVToolButton
- ** created by the Stamper.
- */
- static ACCBPROTO1 void (ACCBPROTO2 *setStamperToolCallback)(void *clientData);
- static ACCB1 void ACCB2 setStamperTool(void *clientData)
- {
- /* As with all the other tools, the Stamper tool should be
- ** sticky if the user holds down the option key while selecting it.
- */
- AVAppSetActiveTool(&stamperTool, (ASBool)((AVSysGetModifiers() & AV_OPTION) != 0));
- }
-
- /* stamperIsEnabled
- ** This is the AVComputeEnabledProc associated with the AVMenuItem, AVToolButton
- ** and AVTool created by the Stamper.
- */
- static ACCBPROTO1 ASBool (ACCBPROTO2 *stamperIsEnabledCallback)(void *permRequired);
- static ACCB1 ASBool ACCB2 stamperIsEnabled(void *permRequired)
- {
- AVDoc avDoc = AVAppGetActiveDoc();
- if (!avDoc)
- return false;
- else {
- PDPerms docPerms = PDDocGetPermissions(AVDocGetPDDoc(avDoc));
- return (!permRequired || (((PDPerms)permRequired & docPerms) != 0));
- }
- }
-
- /* stamperIsMarked
- ** This is the AVComputeMarkedProc associated with the AVMenuItem and AVToolButton
- ** created by the Stamper.
- */
- static ACCBPROTO1 ASBool (ACCBPROTO2 *stamperIsMarkedCallback)(void *clientData);
- static ACCB1 ASBool ACCB2 stamperIsMarked(void *clientData)
- {
- return ((AVAppGetActiveDoc() != NULL) &&
- (AVAppGetActiveTool() == &stamperTool));
- }
-
- /* SetUpTool
- ** Sets up the Stamper's AVToolRec. Note that AVTools are distinct from,
- ** but often invoked by, AVToolButtons.
- */
- static void SetUpTool(void)
- {
- /* Set up the AVToolRec. Don't forget to set the size field! */
- memset(&stamperTool, 0, sizeof(AVToolRec));
- stamperTool.size = sizeof(AVToolRec);
-
- stamperTool.Activate = ASCallbackCreateProto(ActivateProcType, &StamperActivate);
- stamperTool.GetType = ASCallbackCreateProto(GetTypeProcType, &StamperToolGetType);
- stamperTool.AdjustCursor = ASCallbackCreateProto(AdjustCursorProcType, &StamperAdjustCursor);
- stamperTool.DoClick = ASCallbackCreateProto(DoClickProcType, &StamperDoClick);
- /* The stamperIsEnabledCallback is shared between the AVTool,
- ** AVToolButton and AVMenuItem; no need to ASCallbackCreate() it
- ** three times.
- */
- stamperTool.ComputeEnabled = stamperIsEnabledCallback;
- stamperTool.computeEnabledData = NULL;
-
- AVAppRegisterTool(&stamperTool);
-
- AVAppUnregisterNotification(AVAppDidInitializeNSEL,0, SetUpTool, NULL);
- }
-
- static void SetUpToolButton(void)
- {
- /* Insert the Stamper tool button just before the "endToolsGroup"
- ** AVToolButton separator.
- */
- void *stamperIcon = GetStamperToolButtonIcon();
- AVToolBar bar = AVAppGetToolBar();
- AVToolButton separator = AVToolBarGetButtonByName(bar, ASAtomFromString("endToolsGroup"));
-
- stamperToolButton = AVToolButtonNew(Stamper_K, stamperIcon, true, false);
- AVToolButtonSetExecuteProc(stamperToolButton, setStamperToolCallback, NULL);
- AVToolButtonSetComputeEnabledProc(stamperToolButton, stamperIsEnabledCallback, (void *)pdPermEdit);
- AVToolButtonSetComputeMarkedProc(stamperToolButton, stamperIsMarkedCallback, NULL);
- AVToolButtonSetHelpText(stamperToolButton, "Selects Applescript tool button");
-
- AVToolBarAddButton(bar, stamperToolButton, true, separator);
- }
-
- /* Display our About box */
- static ACCB1 void ACCB2 StampAbout(void *data)
- {
- AVAlertNote( "AppleScript" );
- }
-
- static void SetUpMenuItem(void)
- {
- /* Add the "Stamper" menu item immediately after the thread
- ** menu item.
- */
- AVMenu commandMenu, SDKaboutMenu, helpMenu, prefsMenu, toolsMenu;
- AVMenubar MenuBar = AVAppGetMenubar();
- AVMenuItem generalAboutMenuItem, menuItem, aboutMenuItem1, otherItem;
- void *stamperIcon;
- Int32 index;
-
- int isNewCommandMenu = 0; /* A flag to check if the command menu exists */
-
- if (!MenuBar)
- return;
-
- /* Set up our command menuitem. */
- commandMenu = AVMenubarAcquireMenuByName(MenuBar, "ADBE:File");
- if (!commandMenu){
- isNewCommandMenu = 1;
- commandMenu = AVMenuNew ("Acrobat SDK", "ADBE:Acrobat_SDK",gExtensionID);
- }
-
- menuItem = AVMenuItemNew("AppleScript", "ADBE:AppleScriptTool", NULL, false, NO_SHORTCUT, 0, NULL, gExtensionID);
- AVMenuItemSetExecuteProc(menuItem,
- ASCallbackCreateProto(AVExecuteProc, &StampAbout), NULL);
-
- AVMenuAddMenuItem(commandMenu, menuItem, APPEND_MENUITEM);
-
- if (isNewCommandMenu){
- AVMenubarAddMenu(MenuBar,commandMenu ,APPEND_MENU);
- isNewCommandMenu = 0;
- }
-
- AVMenuRelease(commandMenu);
-
- /* Install About command in Help pull-down menu. */
-
- /* Set up our "About" menuitem.
- Its text does not include "About" because the viewer provides that. */
-
- SDKaboutMenu = AVMenubarAcquireMenuByName(MenuBar, "ADBE:AboutSDK");
-
- if (!SDKaboutMenu){
- helpMenu = AVMenubarAcquireMenuByName(MenuBar, "Help");
- SDKaboutMenu = AVMenuNew("About Acrobat SDK", "ADBE:AboutSDK", gExtensionID);
- aboutMenuItem1 = AVMenuItemNew("About Acrobat SDK", "ADBE:AboutSDK", SDKaboutMenu, false, NO_SHORTCUT, 0, NULL, gExtensionID);
- AVMenuAddMenuItem(helpMenu, aboutMenuItem1, APPEND_MENUITEM);
-
- generalAboutMenuItem = AVMenuItemNew("General", "ADBE:AboutGeneral", NULL, false, NO_SHORTCUT, 0, NULL, gExtensionID);
- AVMenuAddMenuItem(SDKaboutMenu, generalAboutMenuItem, APPEND_MENUITEM);
- }
-
- aboutMenuItem1 = AVMenuItemNew("Stamper", "ADBE:AboutStamp", NULL, false, NO_SHORTCUT, 0, NULL, gExtensionID);
- AVMenuItemSetExecuteProc(aboutMenuItem1,
- ASCallbackCreateProto(AVExecuteProc, &StampAbout), NULL);
- AVMenuAddMenuItem(SDKaboutMenu, aboutMenuItem1, APPEND_MENUITEM);
- AVMenuRelease(SDKaboutMenu);
-
- toolsMenu = AVMenubarAcquireMenuByName(MenuBar, "Tools");
-
- /* Find the Thread tool; the Stamper should go right after it.
- */
- otherItem = AVMenubarAcquireMenuItemByName(MenuBar, "Thread");
- stamperIcon = GetStamperMenuItemIcon();
- index = AVMenuGetMenuItemIndex(toolsMenu, otherItem) + 1;
-
- stamperMenuItem = AVMenuItemNew("AppleScript", "ADBE:AppleScript", NULL, true,
- NO_SHORTCUT, 0, stamperIcon, gExtensionID);
- AVMenuItemSetExecuteProc(stamperMenuItem, setStamperToolCallback, NULL);
- AVMenuItemSetComputeEnabledProc(stamperMenuItem, stamperIsEnabledCallback, (void *)pdPermEdit);
- AVMenuItemSetComputeMarkedProc(stamperMenuItem, stamperIsMarkedCallback, NULL);
-
- /* AVMenuItems are added by index, not relative to other AVMenuItems,
- ** unfortunately. Oh well.
- */
- AVMenuAddMenuItem(toolsMenu, stamperMenuItem, index);
-
- /* Release the AVMenuItems that we don't need any more
- */
- AVMenuItemRelease(otherItem);
- AVMenuRelease(toolsMenu);
- }
-
- static ACCB1 void ACCB2 showAboutBox(void *clientData)
- {
- AVAlertNote("Stamper v. 1.0.1");
- }
-
- static void SetUpAboutBox(void)
- {
- AVMenubar bar = AVAppGetMenubar();
- AVMenu aboutExtensionsMenu = AVMenubarAcquireMenuByName(bar, "AboutExtensions");
- aboutMenuItem = AVMenuItemNew("About AppleScript...", "ADBE:AboutAppleScript", NULL,
- false, NO_SHORTCUT, 0, NULL, gExtensionID);
-
- AVMenuItemSetExecuteProc(aboutMenuItem, ASCallbackCreateProto(AVExecuteProc,
- &showAboutBox), NULL);
- AVMenuAddMenuItem(aboutExtensionsMenu, aboutMenuItem, APPEND_MENUITEM);
- }
-
- void SetUpUI(void)
- {
- Stamper_K = ASAtomFromString("ADBE:AppleScript");
-
- /* Create the execute, computeEnabled, and computeMarked callbacks here
- ** because they're shared between the AVTool, AVToolButton and AVMenuItem.
- */
- setStamperToolCallback = ASCallbackCreateProto(AVExecuteProc, &setStamperTool);
- stamperIsEnabledCallback = ASCallbackCreateProto(AVComputeEnabledProc, &stamperIsEnabled);
- stamperIsMarkedCallback = ASCallbackCreateProto(AVComputeMarkedProc, &stamperIsMarked);
-
- stamperCursor = GetStamperCursor();
-
- AVAppRegisterNotification(AVAppDidInitializeNSEL,0, SetUpTool, NULL);
-
- if(ASGetConfiguration(ASAtomFromString("CanEdit"))){
- SetUpToolButton();
- SetUpMenuItem();
- }
- }
-
- void CleanUpUI(void)
- {
-
- AVAppUnregisterNotification(AVAppDidInitializeNSEL,0, SetUpTool, NULL);
- if(stamperToolButton){
- AVToolButtonDestroy(stamperToolButton);
- }
- if(stamperMenuItem){
- AVMenuItemRemove(stamperMenuItem);
- AVMenuItemRelease(stamperMenuItem);
- }
- if(aboutMenuItem){
- AVMenuItemRemove(aboutMenuItem);
- AVMenuItemRelease(aboutMenuItem);
- }
-
- }